//package com.tianhui.consignor.pattern.freightCalculation;
//
//import android.text.TextUtils;
//
//import com.fgs.common.utils.CommonUtil;
//import com.fgs.common.utils.LogUtil;
//import com.tianhui.consignor.mvp.model.enty.OrderInfo;
//import com.xuexiang.xutil.common.StringUtils;
//
///**
// * @author fgs
// * @date 2020/9/23
// * @description
// **/
//public class FreightCalculation implements IFreightCalculation {
//    //亏吨扣除
//    @Override
//    public float getDeductPrice(OrderInfo orderInfo) {
//        //亏吨扣除 = （装车重量 - 结算重量 - 合理路损）* 货物单价（计算结果不能为负数，为负数则为0）
//        float deductPrice;
//        float reasonableWeight = getReasonableWeight(orderInfo);
//        try {
////            deductPrice = (StringUtils.toFloat(orderInfo.tranweightconfirm) - StringUtils.toFloat(orderInfo.recelveweightconfirm) - reasonableWeight) * StringUtils.toFloat(orderInfo.goodsunitprice);
//            deductPrice = getLoseWeight(orderInfo) * StringUtils.toFloat(orderInfo.goodsunitprice);
//        } catch (Exception e) {
//            e.printStackTrace();
//            deductPrice = 0;
//        }
//        if (deductPrice < 0) {
//            deductPrice = 0;
//        }
//        return deductPrice;
//    }
//
//    //合理路耗
//    @Override
//    public float getReasonableWeight(OrderInfo orderInfo) {
//        //合理路耗
//        //1.定额
//        //2.定率 装车重量*路损比例
//
//        float consume = 0.0f;
//        if (orderInfo != null) {
//            if (!TextUtils.isEmpty(orderInfo.consumequota)) {//定额
//                consume = StringUtils.toFloat(orderInfo.consumequota) / 1000;
//            } else if (!TextUtils.isEmpty(orderInfo.consumefixedrate) && !TextUtils.isEmpty(orderInfo.tranweight)) { //定率
//                consume = StringUtils.toFloat(orderInfo.tranweight) * StringUtils.toFloat(orderInfo.consumefixedrate) / 1000;
//            }
//        }
//        return consume;
//    }
//
//    @Override
//    public float getServicePrice(OrderInfo orderInfo, float grants, float otherPrice) {
//        //(运费单价 * 结算重量 + 补助金 + 保险费用 - 亏吨扣除 - 扣除费用) * 税率/100
//        float price = StringUtils.toFloat(orderInfo.tradprice);
//        float settleWeight = StringUtils.toFloat(orderInfo.recelveweightconfirm);
//        float insurePrice = StringUtils.toFloat(orderInfo.insureprice);
//        float result = (price * settleWeight + grants + insurePrice - getDeductPrice(orderInfo) - otherPrice) * orderInfo.handlingfee / 100;
//        return result < 0 ? 0 : result;
//    }
//
//    @Override
//    public float getLoseWeight(OrderInfo orderInfo) {
//
//        String weight;
//        if (!TextUtils.isEmpty(orderInfo.recelveweightconfirm)) {
//            weight = orderInfo.recelveweightconfirm;
//        } else if (!TextUtils.isEmpty(orderInfo.tranweightconfirm)) {
//            weight = orderInfo.tranweightconfirm;
//        } else if (!TextUtils.isEmpty(orderInfo.recelveweight)) {
//            weight = orderInfo.recelveweight;
//        } else {
//            weight = "";
//        }
//        // 装车重量-确认收货重量-合理损路耗
//        LogUtil.print(StringUtils.toFloat(orderInfo.tranweight)+"");
//        LogUtil.print(StringUtils.toFloat(weight)+"");
//        LogUtil.print(getReasonableWeight(orderInfo)+"");
//
//        float loseWeight = StringUtils.toFloat(orderInfo.tranweight) - StringUtils.toFloat(weight) - getReasonableWeight(orderInfo);
//        return loseWeight > 0 ? loseWeight : 0;
//    }
//
//    @Override
//    public String getDriverPrice(OrderInfo orderInfo, float goodsPrice, float price, float grants, float otherPrice) {
//        // 公式：运费单价 x 结算重量 + 补助金 - 亏吨扣除 - 扣除费用
//        float settleWeight = StringUtils.toFloat(orderInfo.recelveweightconfirm);
//        float deductPrice = getDeductPrice(orderInfo);
//        float result = price * settleWeight + grants - deductPrice - otherPrice;
//        return result < 0 ? "0" : CommonUtil.keepTwoDecimal(result + "");
//    }
//
//    @Override
//    public String getTotalPrice(OrderInfo orderInfo, float goodsPrice, float price, float grants, float otherPrice) {
//        // 公式：运费单价 x 结算重量 + 补助金 + 保险费用 + 服务费用 - 亏吨扣除 - 扣除费用
//        float settleWeight = StringUtils.toFloat(orderInfo.recelveweightconfirm);
//        float insurePrice = StringUtils.toFloat(orderInfo.insureprice);
//        float handlingPrice = getServicePrice(orderInfo, grants, otherPrice);
//        float deductPrice = getDeductPrice(orderInfo);
//        float result = price * settleWeight + grants + insurePrice + handlingPrice - deductPrice - otherPrice;
//        return result < 0 ? "0" : CommonUtil.keepTwoDecimal(result + "");
//    }
//
//    @Override
//    public String getTotalTaxPrice(OrderInfo orderInfo, float goodsPrice, float price, float grants, float otherPrice) {
//        // 公式：运费单价 x 结算重量 + 补助金 + 保险费用 + 服务费用 - 亏吨扣除 - 扣除费用
//        float settleWeight = StringUtils.toFloat(orderInfo.recelveweightconfirm);
//        float insurePrice = StringUtils.toFloat(orderInfo.insureprice);
//        float handlingPrice = getServicePrice(orderInfo, grants, otherPrice);
//        float deductPrice = getDeductPrice(orderInfo);
//        float result = price * settleWeight + grants + insurePrice + handlingPrice - deductPrice - otherPrice;
//        return result < 0 ? "0" : CommonUtil.keepTwoDecimal(result + "");
//    }
//
//
//}
